﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chefbook.DataAccessLayer
{
    public partial class ChefbookEntities
    {

        public void ClearDatabase()
        {
            foreach (var category in this.Categories)
            {
                this.DeleteObject(category);
            }
            foreach (var recipe in this.Recipes)
            {
                this.DeleteObject(recipe);
            }
            foreach (var ingredient in this.Ingredients)
            {
                this.DeleteObject(ingredient);
            }
            this.SaveChanges();
        }

        public int NextCategoryId
        {
            get
            {
                var ids = from c in Categories select c.Id;
                if(ids.Count() >0)
                    return ids.Max()+1;
                return 1;
            }
        }

        public int NextRecipeId
        {
            get { return (from r in Recipes select r.Id).Max() + 1; }
        }

        public int NextIngredientId
        {
            get { return (from i in Ingredients select i.Id).Max() + 1; }
        }
    }
}
